package bean;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

/**
 * Description: student  可被监听属性变化
 * Created by E460 on 2017/9/22.
 */
public class StudentWithListenerOfChanage extends  Student {
    protected PropertyChangeSupport propertySupport;
    private String changableValue="old";
    public StudentWithListenerOfChanage(){
        super();
        propertySupport = new PropertyChangeSupport(this);//使本对象有属性改变通知监听器的能力
    }

    public String getChangableValue() {
        return changableValue;
    }

    public void setChangableValue(String changableValue) {
        String oldValue=this.changableValue;
        String newValue=changableValue;
        this.changableValue = newValue;
        //这个在后调用，属性修改后通知监听器
        propertySupport.firePropertyChange("changableValue", oldValue, newValue);
    }
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }

    @Override
    public String toString() {
        return "StudentWithListenerOfChanage{" +
                "changableValue='" + changableValue + '\'' +
                '}';
    }
}
